using System.Diagnostics;
using System.IO;

namespace HardwareUtils
{
    public class ShellExe
    {
        public string StdOut;
        public string StdErr;

        public static ShellExe ExecuteProgram(string executable, string arguments)
        {
            //
            // Setup the process with the ProcessStartInfo class.
            //
            ProcessStartInfo start = new ProcessStartInfo();
            start.FileName = executable; // Specify exe name.
            start.Arguments = arguments;
            start.UseShellExecute = false;
            start.CreateNoWindow = true;
            start.RedirectStandardError = true;
            start.RedirectStandardOutput = true;
            //
            // Start the process.
            //
            var result = new ShellExe();
            using (Process process = Process.Start(start))
            {
                //
                // Read in all the text from the process with the StreamReader.
                //
                 using (StreamReader reader = process.StandardError)
                {
                    result.StdErr = reader.ReadToEnd();
                }
               using (StreamReader reader = process.StandardOutput)
                {
                    result.StdOut = reader.ReadToEnd();
                }
            }
            return result;
        }
    }
}
